package com.powernode.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.shop.domain.Prod;
import com.powernode.shop.service.ProdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZHAOZHENYU
 * @since 2022/10/26
 * 商品管理接口
 */

@RestController
@RequestMapping("/prod/prod")
public class ProdController {

    @Autowired
    private ProdService prodService;

    /**
     * 1、分页查询商品
     * @param page
     * @param prod
     * @return
     */
    @PreAuthorize("hasAuthority('prod:prod:page')")
    @GetMapping("/page")
    public ResponseEntity<Page<Prod>> loadProdPage(Page<Prod> page, Prod prod){
        Page<Prod> prodPage = prodService.loadProdPage(page,prod);
        return ResponseEntity.ok(prodPage);
    }

    /**
     * 2、新增商品
     * @param prod
     * @return
     */
    @PreAuthorize("hasAuthority('prod:prod:save')")
    @PostMapping
    public ResponseEntity<Page<Prod>> saveProd(@RequestBody Prod prod){
        prodService.save(prod);
        return ResponseEntity.ok().build();
    }


}
